home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
FILER
/
SMART.ZIP
/
!SmartDir
/
!Help
next >
Wrap
Text File
|
1998-03-04
|
8KB
|
197 lines
________________________________________________________________________
Program Name: SmartOpenDir
Purpose: Intelligent directory opener
Author: Tony Houghton
Version: 0.23 (4 March 1997)
Requirements: RISC OS 3.1 or later
Status: Freeware
________________________________________________________________________
Contact details:
Tony Houghton
271 Upper Weston Lane
Woolston
Southampton
SO19 9HY
mailto:tonyh@tcp.co.uk
URL:http://homepages.tcp.co.uk/~tonyh/
________________________________________________________________________
Licence
_______
You may freely use, copy and distribute SmartOpenDir provided files are left
unaltered; distribution without the source code is permitted. It may not be
sold for profit beyond normal costs of PD distribution, PD collection CDs or
magazine cover discs. Permission may be granted to bundle SmartOpenDir with
commercial packages, but please ask me first. Source may be reused with
permission.
Overview
________
In general I prefer to use the default options in my filer display, but for
some directories it's more useful to use small icons or full info or sort by
date etc. SmartOpenDir allows this to be done automatically by matching any
directory about to be opened against a set of wildcarded patterns and setting
the filer display options immediately before displaying it.
SmartOpenDir isn't especially user-friendly to configure, but the philosophy
behind it, apart from doing its job as seamlessly as possible, is to achieve
it with minimum programming effort, so the user has to do some of the
calculation of values that might otherwise be left to the program. The source
is provided for anyone who might want to work on improvements in this area.
Loading
_______
It's set up as an application, !SmartDir, which automatically loads the
module with its default Patterns file when run. This is ideal for adding to a
Risc PC boot sequence.
If you want to load the module "manually", uase a line like the following:
RMLoad SmartDir [-a] [-f <Patterns filename>]
Both optional parameters are recommended. -a causes an alias to be set for
Filer_OpenDir, redirecting it to the SmartOpenDir command, which is an
extended version of Filer_OpenDir, opening directories intelligently. If set,
the alias will automatically be reset when the module is killed. The Patterns
filename following the -f parameter is a text file containing a list of
wildcarded directory patterns and their corresponding filer options.
Commands provided
_________________
SmartOpenDir Extended Filer_OpenDir with pattern matching
SmartOpenDirLoad <filename> Loads a replacement Patterns file
Patterns file syntax
____________________
A Patterns file is a text file with one or more lines of the following
syntax:
Pattern Code
Only lines of this form are permitted, do not include any blank lines. Any
number of tabs or spaces may be used between fields. Patterns are matched on
a first matched first used basis, so a specific pattern can be included
before a more general pattern which would otherwise include the specific one.
The Pattern consists of a directory name with the following wildcards:
# Match any single character
* Match any number of characters
% Match until the next directory separator (.) or end of filename
The Code consists of two hexadecimal digits, affecting bits 0-3 of a flags
word. The first digit is the mask. Any bits set in the mask cause the
corresponding bits to be cleared in the flags. The second digit is the value
to be ORed with the masked flags value. The bits have the following meaning:
Bits 0-1: Icon options 0 = Large icons
1 = Small icons
2 = Full info
3 = Reserved
Bits 2-3: Sort options 0 = Sort by name
1 (4) = Sort by type
2 (8) = Sort by size
3 (C) = Sort by date
Therefore the only values likely to be useful for the mask are:
0 leave everything alone
3 affect icon display options only
C affect sort options only
F affect display and sort options
Look at the supplied patterns file for examples. The first 8 patterns are for
C source and header directories etc, opening them with small icons. The
second !NewsDir entry is for Newsbase's "debug" backup news and mail folders,
opening them with small icons and sorted by date. Read on for an explanation
of the last option.
Extended options
________________
SmartOpenDir now has one special case which uses extra digits in the code.
The extended code takes the form:
1nnppqq
where nn, pp and qq are 2-digit hexadecimal values. In this case, the action
for matching directories is to open as if the code were pp unless the number
of files (or subdirectories) in the directory exceeds the given threshold, in
which case it is opened as for code qq.
The final line in the supplied Patterns file dictates that if any directory
which hasn't already been matched is opened, then if it contains more than 24
(&18) objects it will be opened with small icons, otherwise it will use the
configured options.
Precautions
___________
Nothing special, but SmartOpenDir gives you one more reason to shut down the
computer properly before switching off; otherwise the last directory opened
could end up leaving the configuration set that way.
If you manually click any option in the Filer Display submenu, all subsequent
directories will be opened with *all* of the display options as set in that
menu, which may have been affected by SmartOpenDir whose effect was intended
to be temporary.
If using the -a option, it will clash with any other aliases set for
Filer_OpenDir.
Acknowledgements
________________
SmartOpenDir was inspired by Ian Clark's SmallDir. It had a number of
limitations though, and after some experiments it became clear that a
completely different approach was needed.
Technical details
_________________
First let me say that SmartOpenDir is a module, which does not have
particularly complex or extensive code, written in C. Some may consider this
a flagrant breach of RISC OS programming ettiquette, but I have some points
to make in my defence:
The module is under 12K in size, and its total memory use is less than the
minimum size of 32K required by a USR-mode task on a 4MB Archimedes.
If I'd had to worry about the intricacies of assembler, I might not have
bothered writing it at all, and it certainly wouldn't have got done so
quickly.
Writing a module in C was a useful learning exercise, which I intend to
share, time permitting.
SmartOpenDir uses a "two-pronged attack" to ensure that all directories get
opened intelligently and as seamlessly as possible.
Its first line of attack is to implement a new command to replace
Filer_OpenDir, and redirect the original command to it using an alias. The
Filer itself does not use the command when opening a directory when
double-clicked on etc, or when Adjust-clicking a close icon, so
SmartOpenDir's second line of attack is to filter events being sent to the
Filer.
Either way, when a directory is about to be opened it temporarily
reconfigures the computer to use the relevant options, resetting the
configuration the next time the filer receives an event.
SmartOpenDir used to "cheat" a little to find whether the number of objects
in a directory was above or below a given value, using a single SWI with a
reasonably small buffer. This was found to cause crashes when used with CDFS,
so I've switched to a longer-winded approach. Fortunately this does not seem
to cause any delay at opening directories in practice, thanks to directory
caching.